package com.ebpm.designer.line
{
	import com.ebpm.designer.WF;
	import com.ebpm.designer.WP;
	import com.ebpm.designer.WorkPanel;
	import com.ebpm.designer.dir.LineMiddleDir;
	import com.ebpm.designer.dir.LineEndDir;
	import com.ebpm.designer.dir.LineFromDir;
	
	
	public class TDLine extends Line
	{
		
		public var p1:Point;
		public var p2:Point;
		public var startP1:Point;
		public var startP2:Point;
		public function TDLine()
		{
			this.resizeFromDir = new LineFromDir(this, "leftRightIcon");
			this.resizeToDir = new LineEndDir(this, "leftRightIcon");
			this.middleDir = new LineMiddleDir(this, "upDownIcon");
			this.lineHeadType = "up";
			super();
		}
		
		override protected function initPoints(fromX:Number, fromY:Number, x:Number, y:Number):void {
			var itemSize:Number = WF.ITEM_SIZE;
			p1 = new Point(fromX + (itemSize / 2) + this.resizeFromExtraX, (y - fromY)/2 + fromY  + (itemSize / 2) + this.resizeMiddleExtra);
			p2 = new Point(x + (itemSize / 2) + this.resizeToExtraX, p1.y);
			this.points.addItem(p1);
			this.points.addItem(p2);
		}
		
		override public function repaintLine(type:String = "to"):void {
			var fromX:Number = this.sourceItem.nodeContainer.getTopLineX();
			var fromY:Number = this.sourceItem.nodeContainer.getTopLineY();
			var toX:Number = this.targetItem.nodeContainer.getDownLineX();
			var toY:Number = this.targetItem.nodeContainer.getDownLineY();
			this.points.removeAll();
			var extrLength:Number;
			if(WF.LINE_EXT_SIZE / 2 < WF.LINE_HEAD_W) extrLength = WF.LINE_HEAD_W;
			else extrLength = WF.LINE_EXT_SIZE / 2;
			if(this.startPoint.y - this.endPoint.y <= extrLength * 2) {
				WF.wp.removeElement(this);
				this.sourceItem.sourceLines.removeItem(this);
				this.targetItem.targetLines.removeItem(this);
				var line:Line = new TTLine().paint(fromX, fromY, this.targetItem.nodeContainer.getTopLineX(), this.targetItem.nodeContainer.getTopLineY());
				//fromItem 点不变
				this.sourceItem.sourceLines.addItem(line);
				//toItem 的点变了，的是UserTaskContaier的topItem的toLines添加
				this.targetItem.nodeContainer.topItem.targetLines.addItem(line);
				line.sourceItem = this.sourceItem;
				line.targetItem = this.targetItem.nodeContainer.topItem;
			}
			
			paint(fromX, fromY, toX, toY);
			
		}
		
		override public function resizeMiddleItem():void {
			if(this.isFirstMove) {
				this.startP1 = this.p1;
				this.startP2 = this.p2;
				this.isFirstMove = false;
				this.resizeStartExtra = this.resizeMiddleExtra;
			}
			this.resizeMiddleExtra = this.resizeStartExtra + WP.mouseChangeY;
			this.points.removeAll();
			this.points.addItem(this.startPoint);
			this.p1 = new Point(this.startP1.x, this.startP1.y + WP.mouseChangeY);
			this.p2 = new Point(this.startP2.x, this.p1.y);
			this.points.addItem(this.p1);
			this.points.addItem(this.p2);
			this.points.addItem(this.endPoint);
			this.drawLine();
			this.middleDir.y = this.p1.y - (WF.ITEM_SIZE / 2);
		}
		
		//拖拽框移动
		override public function resizeFromItem():void {
			if(this.isFirstMove) {
				this.resizeStartExtra = this.resizeFromExtraX;
				this.isFirstMove = false;
			}
			this.resizeFromExtraX = this.resizeStartExtra + WP.mouseChangeX;
			this.points.removeAll();
			var fromX:Number = this.sourceItem.nodeContainer.getTopLineX();
			var fromY:Number = this.sourceItem.nodeContainer.getTopLineY();
			var toX:Number = this.targetItem.nodeContainer.getDownLineX();
			var toY:Number = this.targetItem.nodeContainer.getDownLineY();
			this.paint(fromX, fromY, toX, toY);
		}
		
		
		override public function resizeEndItem():void {
			if(this.isFirstMove) {
				this.resizeStartExtra = this.resizeToExtraX;
				this.isFirstMove = false;
			}
			this.resizeToExtraX = this.resizeStartExtra + WP.mouseChangeX;
			this.points.removeAll();
			var fromX:Number = this.sourceItem.nodeContainer.getTopLineX();
			var fromY:Number = this.sourceItem.nodeContainer.getTopLineY();
			var toX:Number = this.targetItem.nodeContainer.getDownLineX();
			var toY:Number = this.targetItem.nodeContainer.getDownLineY();
			this.paint(fromX, fromY, toX, toY);
			this.movingTxtByLine();
		}
		
		
		
		
		
		
		
		
		
	}
}